package com.zhuiyun.project.api.sysarticle.controller;

import com.zhuiyun.project.api.friend.model.FriendModel;
import com.zhuiyun.project.api.joingroup.model.JoinGroupModel;
import com.zhuiyun.project.api.sysarticle.model.ArticleModel;
import com.zhuiyun.project.api.sysarticle.model.CommentModel;
import com.zhuiyun.project.api.sysarticle.service.ArticleService;


import com.zhuiyun.project.common.response.CommonResult;
import com.zhuiyun.project.util.RedisUtil;
import com.zhuiyun.project.util.pageUtil.PageRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @ClassName ArticleController
 * @Description TODO
 * @Author 韩佳轩
 * @Date 2023/6/15 10:35
 **/
@RequestMapping("/Sys")
// @RestController = @controller + @responseBody
@RestController
//支持跨越请求
@CrossOrigin
public class ArticleController {
    @Autowired
    private ArticleService articleService;
    /**
     * @Author 韩佳轩
     * @Description app首页文章列表
     * @Date 2023/7/11 15:22
     * @Return com.zhuiyun.project.common.response.CommonResult
     * @param articleModel
     * @param
     */

    @GetMapping("/Article")
    public CommonResult getArticleAll(ArticleModel articleModel ){
        List<ArticleModel> articleAll = articleService.getArticleAll(articleModel);
        if(articleAll!=null){
            return CommonResult.ok(articleAll);
        }
        return CommonResult.error(500,"nm");
    }
    /**
     * @Author 韩佳轩
     * @Description 后台文章管理列表
     * @Date 2023/7/11 15:23
     * @Return com.zhuiyun.project.common.response.CommonResult
     * @param articleModel
     * @param pageRequest
     */

    @GetMapping("/SysArticle")
    public CommonResult getSysArticle(ArticleModel articleModel, PageRequest pageRequest){
        return CommonResult.ok(articleService.getSysArticleAll(articleModel,pageRequest));
    }

    /**
     * @Author 小江
     * @Description //TODO 根据病种查询
     * @Date 21:18 2023/7/11
     **/
    @GetMapping("/ArticleLater")
    public CommonResult ArticleLater(ArticleModel articleModel, PageRequest pageRequest){
         return CommonResult.ok(articleService.ArticleLater(articleModel,pageRequest));
    }
    /**
     * @Author 韩佳轩
     * @Description uniapp上删除文章详情
     * @Date 2023/6/27 16:55
     * @Return com.zhuiyun.project.common.response.CommonResult
     * @param id
     */
    @DeleteMapping("/delArticle")
    public CommonResult getdelArticle(@RequestBody int id){
        int i = articleService.deleteArticle(id);
        if (i > 0) {
            return CommonResult.ok("下架成功");
        } else {
            return CommonResult.error("下架失败");
        }
    }
    /**
     * @Author 韩佳轩
     * @Description 后台管理文章下架
     * @Date 2023/6/27 16:55
     * @Return com.zhuiyun.project.common.response.CommonResult
     * @param id
     */
    @DeleteMapping("/SysdelArticle")
    public CommonResult getsysdelArticle(int id){
        int i = articleService.deleteArticle(id);
        if (i > 0) {
            return CommonResult.ok("下架成功");
        } else {
            return CommonResult.error("下架失败");
        }
    }
    /**
     * @Author 韩佳轩
     * @Description 首页点击跳转文章详情/医师文章列表点击跳转医师文章详情
     * @Date 2023/7/11 15:25
     * @Return com.zhuiyun.project.common.response.CommonResult
     * @param articleModel
     */
    @GetMapping("/ArticleMain")
    public CommonResult getArticleMain(ArticleModel articleModel){
        return CommonResult.ok(articleService.ArticleMain(articleModel));
    }
    /**
     * @Author 韩佳轩
     * @Description app小程序医师的文章列表
     * @Date 2023/7/11 15:27
     * @Return
     * @param
     */
    @GetMapping("/ArticleDoctorList")
    public CommonResult getArticleDoctorList(ArticleModel articleModel){
        return CommonResult.ok(articleService.ArticleDoctorList(articleModel));
    }
    /**
     * @Author 韩佳轩
     * @Description 评论全查
     * @Date 2023/7/11 15:28
     * @Return com.zhuiyun.project.common.response.CommonResult
     * @param commentModel
     */
    @GetMapping("/CommentAll")
    public CommonResult getCommentAll(CommentModel commentModel){
        return CommonResult.ok(articleService.CommentAll(commentModel));
    }
    /**
     * @Author 韩佳轩
     * @Description 添加评论
     * @Date 2023/7/11 15:28
     * @Return com.zhuiyun.project.common.response.CommonResult
     * @param commentModel
     */

    @PostMapping("/addComment")
    public CommonResult addComment(@RequestBody CommentModel commentModel){
        int i = articleService.insertComment(commentModel);
        if (i > 0) {
            return CommonResult.ok("添加成功");
        } else {
            return CommonResult.error("添加失败");
        }
    }
    /**
     * @Author 韩佳轩
     * @Description app文章权限公开私密
     * @Date 2023/7/11 15:31
     * @Return com.zhuiyun.project.common.response.CommonResult
     * @param articleModel
     */
    @GetMapping("/updatePrivacy")
    public CommonResult getupdatePrivacy(ArticleModel articleModel){
        int i = articleService.Privacy(articleModel);
        if (i > 0) {
            return CommonResult.ok("成功");
        } else {
            return CommonResult.error("失败");
        }
    }

    /**
     * @Author 韩佳轩
     * @Description 转发文章的好友列表
     * @Date 2023/7/14 11:19
     * @Return
     * @param friendmodel
     */
    @GetMapping("/friendlist")
    public CommonResult getFriendlist(FriendModel friendmodel){
        return CommonResult.ok(articleService.FriendList(friendmodel));
    }

    /**
     * @Author 韩佳轩
     * @Description  转发文章的群聊列表
     * @Date 2023/7/31 16:54
     * @Return java.util.List<com.zhuiyun.project.api.friend.model.FriendModel>
     * @param  joinGroupModel
     */
    @GetMapping("/Grouplist")
    public CommonResult getGrouplist(JoinGroupModel joinGroupModel){
        return CommonResult.ok(articleService.GroupList(joinGroupModel));
    }


}
